package doublePointer;

/**
 * @author lakersUp
 * @Classname  SortedSquares977
 * @Description 有序数组的平方
 * @Date 2022/2/26 19:42
 * @Version 1.0
 */
public class SortedSquares977 {
    public int[] sortedSquares(int[] nums) {
        int left=0;
        int right=nums.length-1;
        int n=nums.length-1;
        int[] res=new int[nums.length];
        while(left<right){
            if(nums[left]*nums[left]>=nums[right]*nums[right]){
                res[n--]=nums[left]*nums[left];
                left++;
            }else{
                res[n--]=nums[right]*nums[right];
                right--;
            }
        }
        return res;
    }
}
